package es.ikex.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import es.ikex.dao.ProductosDAO;


public class AniadirStock extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ProductosDAO pdao = new ProductosDAO();
		int cantidad = 0;
		boolean error = false;
		try{
			cantidad =  Integer.parseInt(request.getParameter("cantidad"));
		}catch(NumberFormatException e){
			error = true;
			request.setAttribute("error", "El stock debe de ser un numero");
		}
		pdao.masStock(request.getParameter("codigo"),cantidad);
		if(error){
			request.getRequestDispatcher("Admin/aniadirStock.jsp").forward(request, response);
		}else{
			request.removeAttribute("error");
			request.getRequestDispatcher("Controlador/procesarEleccion.jsp?dest=aniadirStock").forward(request, response);
		}
		
	}

}
